package com.web.music.portal.mvc;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.web.music.interfaces.UserService;
import com.web.music.interfaces.SecurityController;
import com.web.music.model.User;

public class ListAllUserController implements Controller {

	private UserService userService;
	private SecurityController securityController;
	
	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) 
	throws Exception 
	{
		User loguser = securityController.getSessionUser(request);
		if (loguser.getIsAdmin().equals("Y")){
			List<User> users = userService.findAll();
			return new ModelAndView("user_listall", "list", users);	
		}
		else{
			return new ModelAndView("redirect:/");
		}

		
	}
	public SecurityController getSecurityController() {
		return securityController;
	}

	public void setSecurityController(
			SecurityController securityController) {
		this.securityController = securityController;
	}
	
}